package ast;

import compiler.OutputFormatter;

public enum Operator {

    ADD("+", OperationType.ARITHMETICAL), 
    SUB("-", OperationType.ARITHMETICAL),
    MUL("*", OperationType.ARITHMETICAL),
    DIV("/", OperationType.ARITHMETICAL),
    AND("&&", OperationType.LOGICAL),
    OR("||", OperationType.LOGICAL),
    LT("<", OperationType.COMPARISON), 
    GT(">", OperationType.COMPARISON),
    LE("<=", OperationType.COMPARISON),
    GE(">=", OperationType.COMPARISON),
    EQ("==", OperationType.COMPARISON),
    NE("!=", OperationType.COMPARISON);

    private String repr;
    private OperationType type;
    
    Operator(String repr, OperationType type) {
        setRepr(repr);
        setType(type);
    }

    public void setRepr(String repr) {
        this.repr = repr;
    }


    public String getRepr() {
        return repr;
    }

	/**
	 * Generates the C source code of the current knot
	 * @param of The OutputFormatter where the code will be generated
	 */    
    public void genC(OutputFormatter of) {
        of.output(getRepr());
    }

    public void setType(OperationType type) {
        this.type = type;
    }

    public OperationType getType() {
        return type;
    }
}
